package ru.urfc.portal.developer_tasks;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import ru.urfc.portal.dao.BasePersistence;
import ru.urfc.portal.model.Branch;
import ru.urfc.portal.model.Client;
import ru.urfc.portal.model.NotificationSettings;
import ru.urfc.portal.model.accounting.Balance;
import ru.urfc.portal.model.accounting.Contract;
import ru.urfc.portal.model.accounting.Contragent;
import ru.urfc.portal.model.accounting.Invoice;
import ru.urfc.portal.model.accounting.InvoiceFacture;
import ru.urfc.portal.model.accounting.Payment;
import ru.urfc.portal.model.admins.User;
import ru.urfc.portal.model.admins.UserRole;
import ru.urfc.portal.model.admins.UserState;
import ru.urfc.portal.model.catalogs.AntennaPolarization;
import ru.urfc.portal.model.catalogs.AntennaType;
import ru.urfc.portal.model.catalogs.DeviceRealization;
import ru.urfc.portal.model.catalogs.DeviceState;
import ru.urfc.portal.model.catalogs.DeviceType;
import ru.urfc.portal.model.catalogs.NetLicenseState;
import ru.urfc.portal.model.catalogs.NetState;
import ru.urfc.portal.model.catalogs.RayClass;
import ru.urfc.portal.model.documents.AttachedFile;
import ru.urfc.portal.model.documents.Document;
import ru.urfc.portal.model.documents.DocumentState;
import ru.urfc.portal.model.documents.DocumentStateChange;
import ru.urfc.portal.model.documents.DocumentType;
import ru.urfc.portal.model.radio.DeviceCertificate;
import ru.urfc.portal.model.radio.DeviceMeasurement;
import ru.urfc.portal.model.radio.DeviceSector;
import ru.urfc.portal.model.radio.DeviceSectorFrequencies;
import ru.urfc.portal.model.radio.DeviceStateChange;
import ru.urfc.portal.model.radio.DeviceWithExtra;
import ru.urfc.portal.model.radio.NetFrequencyAssignment;
import ru.urfc.portal.model.radio.NetLicense;
import ru.urfc.portal.model.radio.NetWithLicense;
import ru.urfc.portal.services.DmsCategory;
import ru.urfc.portal.ui.client.Constants;
import ru.urfc.portal.ui.client.model.catalogs.InvoiceState;

@Stateless
public class Initializer {
	public static final String CONTRAGENT_NAME_MTS = "ОАО МТС";
	public static final String CONTRAGENT_NAME_QQ = "Рога и Со";
	public static final String CLIENT_MTS_USER_PHONE = "++MTS";
	public static final String CLIENT_MTS_USER_EMAIL = "1st@mts.ru";
	public static final String CLIENT_MTS_DEVICE_NUMBER = "++DeviceMTS";
	public static final String CLIENT_MTS_NET_LICENSE_NUMBER = "++LicenseMTS";
	public static final String CLIENT_MTS_CONTRACT_NUMBER = "++ContractMTS";
	public static final String CLIENT_MTS_INVOICE_NUMBER = "++InvoiceMTS";
	public static final String CLIENT_MTS_DOCUMENT_ATTACHMENT_FILE_NAME = "++DocumentAttachmentMTS";
	
	@EJB BasePersistence basePersistence;
	
	private <T> T persist(T entity) {
		return basePersistence.persist(entity);		
	}

	public Object createEis(SysObjects sysObjects) {
		for (DeviceCertificate certificate: sysObjects.certificates) {
			persist(certificate);
		}
		return null;
	}

	public Object createSys(SysObjects sysObjects) {
		return createItems(sysObjects, basePersistence);
	}

	public SysObjects createSpectr() {
		SpectrObjects spectrObjects = new SpectrObjects(basePersistence);
		return spectrObjects.sysObjects;
	}

	static public class SpectrObjects extends SpectrItems {
		BasePersistence basePersistence;
		
		public SpectrObjects(BasePersistence basePersistence) {
			this.basePersistence = basePersistence;
			createItems(basePersistence);
			create(new Contragent(1L,
					"+712123", "2402233", "spam@mts.ru", "620000", "Екатеринбург", "Воли 65", CONTRAGENT_NAME_MTS, "620000", "Екатеринбург", "Воли 63",
					"123123123", "12341234", "546345634634", new Date(), "Президент, Михаил Шамолин",
					"СКБ", "Екатеринбург", "Куйбышева", "21312312", "123123123", "678456", "хозрасчет"));
			create(new Contragent(2L,
					"+712123", "23452345", "xxx@roga.com", "620000", "Екатеринбург", "Воли 65", CONTRAGENT_NAME_QQ, "620000", "Екатеринбург", "Воли 63",
					"234234234", "123123123", "546345634634", new Date(), "Главнокомандующий, О. Бендер",
					"СКБ", "Екатеринбург", "Куйбышева", "21312312", "123123123", "678456", "хозрасчет"));
			create(new Contragent(3L,
					"+712123", "34563456", "xxx@ivanov.com", "620000", "Екатеринбург", "Воли 65", "ИП Какой То", "620000", "Екатеринбург", "Воли 63",
					"345345345", "123123123", "546345634634", new Date(), "Некто Иванов",
					"СКБ", "Екатеринбург", "Куйбышева", "21312312", "123123123", "678456", "хозрасчет"));		
		}
		
		<T extends Object> T persist(T entity) {
			if (basePersistence == null) {
				return super.persist(entity);
			}
			return basePersistence.persist(entity);
		};

		SysObjects sysObjects = new SysObjects();

		private Contragent create(Contragent contragent) {
			persist(contragent);
			boolean mts = contragent.getId() == 1L;
			Client client = sysObjects.create(new Client(mts? 1L: null, contragent.getId(), sysObjects.BRANCH_SVERD, false, false), contragent.getId());
			if (mts) {
				NetWithLicense mtsNet = create(client, new NetWithLicense(contragent, "GSM 1900", "Масква", NET_PLANNED), true);
				create(client, new DeviceWithExtra(mtsNet,
					deviceType1, CLIENT_MTS_DEVICE_NUMBER, 4, 1000, DEVICE_STATE_ACTIVE,
					"Екатеринбург", "Ленина 50", "qq", "1", "qq", "2",
					realization1, 56.33, 99.23, new BigDecimal(100)));
				persist(new NetLicense(mtsNet, CLIENT_MTS_NET_LICENSE_NUMBER, new Date(), new Date(), NET_LICENSE_ACTIVE));
				Contract mtsContract = persist(new Contract(contragent, CLIENT_MTS_CONTRACT_NUMBER, new Date(), null)); 
				persist(new Invoice(contragent, mtsContract, CLIENT_MTS_INVOICE_NUMBER, "Услуги (работы) по обеспечению ...", new Date(), 82D, 18D, 100D, InvoiceState.BILLED, 0.0));
			}
			
			create(client, new NetWithLicense(contragent, "GSM 1990", "Екатеринбург", NET_PLANNED), false);
			create(client, new NetWithLicense(contragent, "GSM 1999", "Пермь", NET_METERING), false);
			
			Contract contract = persist(new Contract(contragent, "123123123", new Date(), new Date())); 
			persist(new Contract(contragent, "342342342", new Date(), new Date()));
			persist(new Contract(contragent, "565463452", new Date(), new Date()));
			
			persist(new Balance(contragent, 2009, 11, new BigDecimal(110.50)));
			persist(new Balance(contragent, 2009, 12, new BigDecimal(120.50)));
			persist(new Balance(contragent, 2010, 01, new BigDecimal(10.50)));

			Invoice invoice1 = persist(new Invoice(contragent, contract, "342112312", "Услуги (работы) по обеспечению ...", new Date(), 82.00D, 18.00D, 100.00D, InvoiceState.BILLED, 0.0));
			Invoice invoice2 = persist(new Invoice(contragent, contract, "342112312", "Услуги по управлению ...", new Date(), 160.55D, 0D, 160.55D, InvoiceState.PAID, 12.34));
			Invoice invoice3 = persist(new Invoice(contragent, contract, "342112312", "Оформление справок по запросам", new Date(), 100.86D, 22.14D, 123D, InvoiceState.BILLED, 20.00));

			persist(new Payment(contragent, invoice1, "664434232", new Date(), new BigDecimal(1000)));
			persist(new Payment(contragent, invoice2, "664434233", new Date(), new BigDecimal(1000)));
			persist(new Payment(contragent, invoice3, "664434234", new Date(), new BigDecimal(1000)));
			
			persist(new InvoiceFacture(contragent, "67543", "С/ф. Услуги (работы) по обеспечению ...", new Date(), new BigDecimal(82.34D)));
			persist(new InvoiceFacture(contragent, "67544", "С/ф. Услуги по управлению ...", new Date(), new BigDecimal(200)));
			
			return contragent;
		}

		private NetWithLicense create(Client client, NetWithLicense netWithLicense, boolean first) {
			persist(netWithLicense);
			persist(new NetLicense(netWithLicense, "654321", new Date(), new Date(), NET_LICENSE_ACTIVE));
			persist(new NetLicense(netWithLicense, "654321", new Date(), new Date(), NET_LICENSE_STOPPED));
			persist(new NetLicense(netWithLicense, "654321", new Date(), new Date(), NET_LICENSE_ANNULATED));
			
			persist(new NetFrequencyAssignment(netWithLicense, 2000000L, 2010000L, 3));
			persist(new NetFrequencyAssignment(netWithLicense, 2020000L, 2030000L, 4));
			
			DeviceWithExtra device =
				create(client, new DeviceWithExtra(netWithLicense,
							deviceType1, "11122", 4, 1000, DEVICE_STATE_ACTIVE,
							"Екатеринбург", "Ленина 50", "qq", "1", "qq", "2",
							realization1, 56.33, 99.23, new BigDecimal(100)));
			create(client, new DeviceWithExtra(netWithLicense,
							deviceType2, "12323", 4, 1000, DEVICE_STATE_PLANNED,
							"Екатеринбург", "Высотскоко 14", "qq", "1", "qq", "2",
							realization1, 56.33, 99.23, new BigDecimal(200)));
			create(client, new DeviceWithExtra(netWithLicense,
							deviceType4, "12323", 4, 1000, DEVICE_STATE_RESERVED,
							"Асбест", "Асбестовский 34", "qq", "1", "qq", "2",
							realization2, 56.33, 99.23, new BigDecimal(200)));
			if (first && client.getContragentId() == 1L) {
				Document document =	sysObjects.create(new Document(client, device, sysObjects.DOCUMENT_TYPE_STOP_EXPLOITATION, new Date(), new Date(), sysObjects.DOCUMENT_STATE_REFUSED));
				sysObjects.persist(new AttachedFile(document, CLIENT_MTS_DOCUMENT_ATTACHMENT_FILE_NAME, "Данные XXX"));
			}
			return netWithLicense;
		}
		
		private DeviceWithExtra create(Client client, DeviceWithExtra deviceWithExtra) {
			persist(deviceWithExtra);
			DeviceSector sector1 = persist(new DeviceSector(deviceWithExtra,
					ANTENNA_TYPE_BEAM_FORMED, ANTENNA_POLARIZATION_HORIZONTAL,
					100, 45D, 55, 66D, 52, Arrays.asList(RAY_CLASS_1, RAY_CLASS_2, RAY_CLASS_3)));
			persist(new DeviceSectorFrequencies(sector1, 1024000L, 3360000L));
			persist(new DeviceSectorFrequencies(sector1, 2048000L, 4800000L));

			DeviceSector sector2 = persist(new DeviceSector(deviceWithExtra, ANTENNA_TYPE_XXX_FORMED, ANTENNA_POLARIZATION_VERTICAL,
					100, 45D, 35, 67D, 9, Arrays.asList(RAY_CLASS_1, RAY_CLASS_3)));
			persist(new DeviceSectorFrequencies(sector2, 2024000L, 4360000L));
			persist(new DeviceSectorFrequencies(sector2, 3048000L, 5800000L));
			
			sysObjects.add(new DeviceCertificate(DeviceCertificate.STATUS_ACTIVE, deviceWithExtra, "Working", "12123123", new Date(), new Date()));
			sysObjects.add(new DeviceCertificate(null, deviceWithExtra, "StatusNull", "12423424", new Date(), new Date()));
			sysObjects.add(new DeviceCertificate(2L, deviceWithExtra, "Annul", "12423425", new Date(), new Date()));

			SysItems sys = sysObjects;
			sysObjects.create(new Document(client, deviceWithExtra, sys.DOCUMENT_TYPE_STOP_EXPLOITATION, new Date(), new Date(), sys.DOCUMENT_STATE_REFUSED));
			sysObjects.create(new Document(client, deviceWithExtra, sys.DOCUMENT_TYPE_CALCULATE_ZONE, new Date(), new Date(), sys.DOCUMENT_STATE_SATISFIED));
			sysObjects.create(new Document(client, deviceWithExtra, sys.DOCUMENT_TYPE_IMPORT_EXPERTISE, new Date(), new Date(), sys.DOCUMENT_STATE_SATISFIED));
			sysObjects.create(new Document(client, deviceWithExtra, sys.DOCUMENT_TYPE_NOISE_ELIMINATION, new Date(), new Date(), sys.DOCUMENT_STATE_IN_PROGRESS));
			sysObjects.create(new Document(client, deviceWithExtra, sys.DOCUMENT_TYPE_PARAMETERS_CONFIRMATION, new Date(), new Date(), sys.DOCUMENT_STATE_IN_PROGRESS));
			sysObjects.create(new Document(client, deviceWithExtra, sys.DOCUMENT_TYPE_SERVICE_ORDER, new Date(), new Date(), sys.DOCUMENT_STATE_IN_PROGRESS));
			sysObjects.create(new Document(client, deviceWithExtra, sys.DOCUMENT_TYPE_TURNON_NOTICE, new Date(), new Date(), sys.DOCUMENT_STATE_IN_PROGRESS));
			sysObjects.create(new Document(client, deviceWithExtra, sys.DOCUMENT_TYPE_LETTER, new Date(), new Date(), sys.DOCUMENT_STATE_IN_PROGRESS));
			sysObjects.create(new Document(client, deviceWithExtra, sys.DOCUMENT_TYPE_DOCS_ORDER, new Date(), new Date(), sys.DOCUMENT_STATE_IN_PROGRESS));
			sysObjects.create(new Document(client, deviceWithExtra, sys.DOCUMENT_TYPE_REG_DATA_CHANGE, new Date(), new Date(), sys.DOCUMENT_STATE_IN_PROGRESS));
			
			persist(new DeviceMeasurement(deviceWithExtra, "123123123", new Date()));
			persist(new DeviceMeasurement(deviceWithExtra, "154656542", new Date()));
			
			persist(new DeviceStateChange(deviceWithExtra, new Date(), DEVICE_STATE_ACTIVE));
			persist(new DeviceStateChange(deviceWithExtra, new Date(), DEVICE_STATE_RESERVED));
			persist(new DeviceStateChange(deviceWithExtra, new Date(), DEVICE_STATE_PLANNED));
			
			return deviceWithExtra;		
		}
	
	}
	
	static public class SysObjects extends SysItems {
		Branch BRANCH_SVERD = persist(Branch.SVERD);
		Branch BRANCH_KURGAN = persist(Branch.KURGAN);
//		Branch BRANCH_TYUMEN = persist(Branch.TYUMEN);
//		Branch BRANCH_CHEL = persist(Branch.CHEL);
		NotificationSettings GLOBAL_NOTIFICATION_SETTINGS = persist(new NotificationSettings(null, false, true, true, 20, true, 2, 1));
		{
			GLOBAL_NOTIFICATION_SETTINGS.setGlobal(true);
		}
		public List<DeviceCertificate> certificates = new ArrayList<DeviceCertificate>();

		private Client create(Client client, Long contragentId) {
			client.setNotificationSettings(new NotificationSettings(client, false, true, true, 20, true, 2, 1));
			persist(client);
			if (contragentId == 1L) {
				persist(new User(1L, client, "Пользователь", "Почетный", "МТС", CLIENT_MTS_USER_EMAIL, CLIENT_MTS_USER_PHONE, USER_ROLE_ADMIN, USER_STATE_ACTIVE));
			}
			persist(new User(client, "Имя1", "Отчество1", "Фамилия1", "qq123" + contragentId + "@mail.ru", "+7904878787", USER_ROLE_ADMIN, USER_STATE_ACTIVE));
			persist(new User(client, "Имя2", "Отчество2", "Фамилия2", "qq124" + contragentId + "@mail.ru", "+7904878787", USER_ROLE_USER, USER_STATE_DISABLED));
			persist(new User(client, "Имя3", "Отчество3", "Фамилия3", "qq125" + contragentId + "@mail.ru", "+7904878787", USER_ROLE_USER, USER_STATE_INVITED));
			return client;
		}

		public Document create(Document document) {
			persist(document);
			persist(new DocumentStateChange(document, new Date(), DOCUMENT_STATE_IN_PROGRESS, "Первый!"));
			persist(new DocumentStateChange(document, new Date(), DOCUMENT_STATE_SATISFIED, "Второй"));
			persist(new DocumentStateChange(document, new Date(), DOCUMENT_STATE_REFUSED, "Последний!!"));
			persist(new AttachedFile(document, "Приложение 1", "Данные"));
			persist(new AttachedFile(document, "Приложение 2", "Данные 2"));
			return document;
		}

		public void add(DeviceCertificate deviceCertificate) {
			certificates.add(deviceCertificate);
		}

	}

	static class SysItems extends Items {		
		UserRole USER_ROLE_ADMIN = persist(new UserRole(CODE_USER_ROLE_ADMIN, "администратор")); 
		UserRole USER_ROLE_USER = persist(new UserRole(CODE_USER_ROLE_USER, "пользователь"));

		UserState USER_STATE_ACTIVE = create(ru.urfc.portal.ui.client.model.catalogs.UserState.ACTIVE);
		UserState USER_STATE_DISABLED = create(ru.urfc.portal.ui.client.model.catalogs.UserState.DISABLED);
		UserState USER_STATE_INVITED = create(ru.urfc.portal.ui.client.model.catalogs.UserState.INVITED);
		
		DocumentType DOCUMENT_TYPE_STOP_EXPLOITATION = persist(new DocumentType(Constants.DOCUMENT_TYPE_STOP_EXPLOITATION, "Отказ от эксплуатации РЭС", "Заявка", Document.EMPTY_DATA));
		DocumentType DOCUMENT_TYPE_CALCULATE_ZONE = persist(new DocumentType(Constants.DOCUMENT_TYPE_CALCULATE_ZONE, "Расчёт зоны уверенного приёма", "Заявка", Document.EMPTY_DATA));
		DocumentType DOCUMENT_TYPE_IMPORT_EXPERTISE = persist(new DocumentType(Constants.DOCUMENT_TYPE_IMPORT_EXPERTISE, "Проведение экспертизы для ввоза РЭС", "Заявка", Document.EMPTY_DATA));
		DocumentType DOCUMENT_TYPE_NOISE_ELIMINATION = persist(new DocumentType(Constants.DOCUMENT_TYPE_NOISE_ELIMINATION, "Устранение помех", "Заявка", Document.EMPTY_DATA));
		DocumentType DOCUMENT_TYPE_PARAMETERS_CONFIRMATION = persist(new DocumentType(Constants.DOCUMENT_TYPE_PARAMETERS_CONFIRMATION, "Оформление подтверждения технических параметров", "Заявка", Document.EMPTY_DATA));
		DocumentType DOCUMENT_TYPE_SERVICE_ORDER = persist(new DocumentType(Constants.DOCUMENT_TYPE_SERVICE_ORDER, "Оказание услуг", "Заявка", Document.EMPTY_DATA));
		DocumentType DOCUMENT_TYPE_TURNON_NOTICE = persist(new DocumentType(Constants.DOCUMENT_TYPE_TURNON_NOTICE, "Уведомление о включении", "Уведомление", Document.EMPTY_DATA));
		DocumentType DOCUMENT_TYPE_LETTER = persist(new DocumentType(Constants.DOCUMENT_TYPE_LETTER, "Письмо", "Письмо", Document.EMPTY_DATA));
		DocumentType DOCUMENT_TYPE_DOCS_ORDER = persist(new DocumentType(Constants.DOCUMENT_TYPE_DOCS_ORDER, "Заказ документов", "Заявка", Document.EMPTY_DATA));
		DocumentType DOCUMENT_TYPE_REG_DATA_CHANGE = persist(new DocumentType(Constants.DOCUMENT_TYPE_REG_DATA_CHANGE, "Изменение регистрационных данных", "Заявка", Document.EMPTY_DATA));
		
		DmsCategory dummy1 = create(DmsCategory.createCategory(DOCUMENT_TYPE_CALCULATE_ZONE, "pstcimlg800fg0000ig7l4ejmijd4r4o;pstcimlg800fg0000ig7l3ns31jqgnng;pstcimlg800fg0000ig7l4naepl71roo;pstcimlg800fg0000ig7l59f3hi4o0h8;pstcimlg800fg0000ig7l515r8dtqdg8"));
		DmsCategory dummy2 = create(DmsCategory.createCategory(DOCUMENT_TYPE_NOISE_ELIMINATION, "pstcimlg800fg0000iga42csspu42i60;pstcimlg800fg0000iga42sn79hbup20;pstcimlg800fg0000iga4338jgd83akc;pstcimlg800fg0000iga4387v5ma3mp0;pstcimlg800fg0000iga43hgs51p3r48"));
		DmsCategory dummy3 = create(DmsCategory.createCategory(DOCUMENT_TYPE_STOP_EXPLOITATION, "pstcimlg800fg0000ig7lcg44lh4v5bo;pstcimlg800fg0000ig7lcn2e8v804v0;pstcimlg800fg0000ig7lcuke92c16e4;pstcimlg800fg0000ig7ldagfd5f80t8;pstcimlg800fg0000ig7ld4emam2l5kg"));
		DmsCategory dummy4 = create(DmsCategory.createCategory(DOCUMENT_TYPE_IMPORT_EXPERTISE,"pstcimlg800fg0000ig7l9imfps5g180;pstcimlg800fg0000ig7l9or80ojml6k;pstcimlg800fg0000ig7la1j8ptog5i8;pstcimlg800fg0000ig7laf91q8jf788;pstcimlg800fg0000ig7la9r55gfrcnc"));
		DmsCategory dummy5 = create(DmsCategory.createCategory(DOCUMENT_TYPE_SERVICE_ORDER,"pstcimlg800fg0000iga4428lqlfpgrc;pstcimlg800fg0000iga446n1eb1bkg4;pstcimlg800fg0000iga44d3e7prv038;pstcimlg800fg0000iga44ive4m8es80;pstcimlg800fg0000iga44v1agtqqf5g"));
		DmsCategory dummy6 = create(DmsCategory.createCategory(DOCUMENT_TYPE_TURNON_NOTICE,"pstcimlg800fg0000ig7ldo76q9i7hqo;pstcimlg800fg0000ig7ldsfguj19amc;pstcimlg800fg0000ig7lekf97a06n18;pstcimlg800fg0000ig7lblnfmdokj8k;pstcimlg800fg0000ig7leqg9ei9cgmk"));
		DmsCategory dummy7 = create(DmsCategory.createCategory(DOCUMENT_TYPE_LETTER,"pstcimlg800fg0000ig7lim353su4h5g;pstcimlg800fg0000ig7liq8oume1tn4;pstcimlg800fg0000ig7ll7b1gvgj4e8;pstcimlg800fg0000ig7lll6aaenp5co;pstcimlg800fg0000ig7llfmtvvt40n4"));
        DmsCategory dummy8 = create(DmsCategory.createCategory(DOCUMENT_TYPE_DOCS_ORDER,"pstcimlg800fg0000ig7lhjm22kqgu00;pstcimlg800fg0000ig7lhnt6p6ldnc0;pstcimlg800fg0000ig7lhsabcm89guc;pstcimlg800fg0000ig7li4mbkq3tsbg;pstcimlg800fg0000ig7li0msaag0u1c"));
		DmsCategory dummy9 = create(DmsCategory.createCategory(DOCUMENT_TYPE_REG_DATA_CHANGE,"pstcimlg800fg0000ig7lfftu2sg345k;pstcimlg800fg0000ig7lfl17hid6je0;pstcimlg800fg0000ig7lfr0g6sppfv0;pstcimlg800fg0000ig7lg7b49qdv02s;pstcimlg800fg0000ig7lg13fgsocphc"));
		DmsCategory dummy10 = create(DmsCategory.createCategory(DOCUMENT_TYPE_PARAMETERS_CONFIRMATION,"pstcimlg800fg0000ig7lavq5nrqun5c;pstcimlg800fg0000ig7lb57ur3059jk;pstcimlg800fg0000ig7lb9gr4qd5sls;pstcimlg800fg0000ig7lblnfmdokj8k;pstcimlg800fg0000ig7lbf9vb2vbohs"));
		
		DocumentState DOCUMENT_STATE_DRAFT = create(ru.urfc.portal.ui.client.model.catalogs.DocumentState.DRAFT);
		DocumentState DOCUMENT_STATE_SUBMITTED = create(ru.urfc.portal.ui.client.model.catalogs.DocumentState.SUBMITTED);
		DocumentState DOCUMENT_STATE_SATISFIED = create(ru.urfc.portal.ui.client.model.catalogs.DocumentState.SATISFIED);
		DocumentState DOCUMENT_STATE_IN_PROGRESS = create(ru.urfc.portal.ui.client.model.catalogs.DocumentState.IN_PROGRESS);
		DocumentState DOCUMENT_STATE_REFUSED = create(ru.urfc.portal.ui.client.model.catalogs.DocumentState.REFUSED);
		

		DmsCategory create(DmsCategory[] dmsCategs) {
			for (DmsCategory dmsCategory : dmsCategs) {
				persist(dmsCategory);
			}
			return null;
		}
		
		DocumentState create(ru.urfc.portal.ui.client.model.catalogs.DocumentState item) {
			return persist(new DocumentState(item.getCode(), item.getText()));
		}

		UserState create(ru.urfc.portal.ui.client.model.catalogs.UserState item) {
			return persist(new UserState(item.getCode(), item.getText()));
		}

	}
	
	static class SpectrItems extends Items {
		NetState NET_ANNULATED = create(ru.urfc.portal.ui.client.model.catalogs.NetState.ANNULATED);
		NetState NET_APPROVED = create(ru.urfc.portal.ui.client.model.catalogs.NetState.APPROVED);
		NetState NET_ENABLED = create(ru.urfc.portal.ui.client.model.catalogs.NetState.ENABLED);
		NetState NET_METERING = create(ru.urfc.portal.ui.client.model.catalogs.NetState.METERING);
		NetState NET_NOT_APPROVED = create(ru.urfc.portal.ui.client.model.catalogs.NetState.NOT_APPROVED);
		NetState NET_ON_APPROVAL = create(ru.urfc.portal.ui.client.model.catalogs.NetState.ON_APPROVAL);
		NetState NET_PLANNED = create(ru.urfc.portal.ui.client.model.catalogs.NetState.PLANNED);
		
		NetLicenseState NET_LICENSE_ANNULATED = create(ru.urfc.portal.ui.client.model.catalogs.NetLicenseState.ANNULATED);
		NetLicenseState NET_LICENSE_ACTIVE = create(ru.urfc.portal.ui.client.model.catalogs.NetLicenseState.ACTIVE);
		NetLicenseState NET_LICENSE_EXPIRED = create(ru.urfc.portal.ui.client.model.catalogs.NetLicenseState.EXPIRED);
		NetLicenseState NET_LICENSE_STOPPED = create(ru.urfc.portal.ui.client.model.catalogs.NetLicenseState.STOPPED);

		DeviceType deviceType1 = persist(new DeviceType("КВРПЦ-221К"));
		DeviceType deviceType2 = persist(new DeviceType("КВРПЦ-222К"));
		DeviceType deviceType3 = persist(new DeviceType("КВРПЦ-223К"));
		DeviceType deviceType4 = persist(new DeviceType("КВРПЦ-224К"));
		DeviceType deviceType5 = persist(new DeviceType("КВРПЦ-225К"));
		DeviceType deviceType6 = persist(new DeviceType("КВРПЦ-226К"));
		
		DeviceState DEVICE_STATE_ACTIVE = create(ru.urfc.portal.ui.client.model.catalogs.DeviceState.ACTIVE);
		DeviceState DEVICE_STATE_PLANNED = create(ru.urfc.portal.ui.client.model.catalogs.DeviceState.PLANNED);
		DeviceState DEVICE_STATE_RESERVED = create(ru.urfc.portal.ui.client.model.catalogs.DeviceState.RESERVED);
		DeviceState DEVICE_STATE_DEREGISTERED = create(ru.urfc.portal.ui.client.model.catalogs.DeviceState.DEREGISTERED);
		DeviceState DEVICE_STATE_ACCEPTED = create(ru.urfc.portal.ui.client.model.catalogs.DeviceState.ACCEPTED);
		
		DeviceRealization realization1 = persist(new DeviceRealization("стационарное"));
		DeviceRealization realization2 = persist(new DeviceRealization("не стационарное"));
		
		AntennaType ANTENNA_TYPE_BEAM_FORMED = persist(new AntennaType("BEAM_FORMED", "направленная"));
		AntennaType ANTENNA_TYPE_XXX_FORMED = persist(new AntennaType("XXX_FORMED", "не направленная"));
		
		AntennaPolarization ANTENNA_POLARIZATION_HORIZONTAL = persist(new AntennaPolarization("HORIZONTAL", "горизонтальная"));
		AntennaPolarization ANTENNA_POLARIZATION_VERTICAL = persist(new AntennaPolarization("VERTICAL", "вертикальная"));
		
		RayClass RAY_CLASS_1 = persist(new RayClass("1"));
		RayClass RAY_CLASS_2 = persist(new RayClass("2"));
		RayClass RAY_CLASS_3 = persist(new RayClass("3"));		

		NetLicenseState create(ru.urfc.portal.ui.client.model.catalogs.NetLicenseState item) {
			return persist(new NetLicenseState(item.getCode(), item.getText()));
		}

		NetState create(ru.urfc.portal.ui.client.model.catalogs.NetState item) {
			return persist(new NetState(item.getCode(), item.getText()));
		}
		
		DeviceState create(ru.urfc.portal.ui.client.model.catalogs.DeviceState item) {
			return persist(new DeviceState(new Long(item.getCode()), item.getText()));
		}
		
	}
	
	static class Items implements Constants {
		List<Object> entities = new ArrayList<Object>();

		<T extends Object> T persist(T entity) {
			entities.add(entity);
			return entity;
		}


		void createItems(BasePersistence basePersistence) {
			for (Object entity: entities) {
				basePersistence.persist(entity);
			}
		}

	}

	private <T extends Items> T createItems(T items, BasePersistence basePersistence) {
		items.createItems(basePersistence);
		return items;
	}
	
}
